<?php

namespace App\Remote\Tiger\OpenShop;

use App\Exceptions\BaseException;
use App\Remote\Tiger\Remote;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class OpenShopRemote extends Remote
{

    /**
     * 更新门店经理
     *
     * @param int $uid
     * @param bool $cached
     * @return mixed|void
     * @throws BaseException
     * @throws GuzzleException
     */
    public static function setUserManageId(int $shopCode, int $type, int $uid, string $uname)
    {
        $userOrganization = function () use ($uid, $type, $uname, $shopCode) {
            return self::customRequest(
                "internal/openShop/changeManager",
                RequestAlias::METHOD_POST,
                [
                    'uid'      => $uid,
                    'type'     => $type,
                    'uname'    => $uname,
                    'shopCode' => $shopCode
                ]
            );
        };
        return $userOrganization();
    }

    /**
     * 根据门店ID门店属性
     * @param int $shopId
     * @return mixed|void
     * @throws BaseException
     * @throws GuzzleException
     */
    public static function getShopPatternByShopId(int $shopId)
    {
        return self::customRequest(
            "internal/shop/getShopPatternByShopId",
            RequestAlias::METHOD_GET,
            [
                'shopId' => $shopId,
            ]
        );
    }


    /**
     * 根据门店ID查询门店属性
     * @param array $shopIds
     * @param string $type
     * @return mixed|void
     * @throws BaseException
     * @throws GuzzleException
     */
    public static function getShopAttributeByShopIds(array $shopIds, string $type = '')
    {
        return self::customRequest(
            'internal/shop/getShopAttributeByShopIds',
            RequestAlias::METHOD_GET,
            [
                'shopIds' => implode(',', $shopIds),
                'type'    => $type,
            ]
        );
    }


    /**
     * 获取门店开店状态在确认建店之后的门店
     * @return mixed|void
     * @throws BaseException
     * @throws GuzzleException
     */
    public static function getShops()
    {
        return self::customRequest(
            'internal/openShop/getShops',
            RequestAlias::METHOD_GET
        );
    }

    /**
     * 根据门店code查询开店订单手机号
     * @param int $shopCode
     * @return mixed|void
     * @throws BaseException
     * @throws GuzzleException
     */
    public static function getShopMobileByShopCode(int $shopCode)
    {
        return self::customRequest(
            'internal/shop/getShopMobileByShopCode',
            RequestAlias::METHOD_GET,
            [
                'shopCode' => $shopCode
            ]
        );
    }

    /**
     * 根据稽核人员id查询对应门店区域
     * @param array $userIds
     * @param string $regionCode
     * @return mixed|void
     * @throws BaseException
     * @throws GuzzleException
     */
    public static function getShopCruiseManageArea(array $userIds = [], string $regionCode = '')
    {
        return self::customCacheRequest(
            'internal/shop/getShopCruiseManageArea',
            RequestAlias::METHOD_GET,
            [
                'userIds'    => $userIds ? implode(',', $userIds) : '',
                'regionCode' => $regionCode,
            ],
            null,
            5 * 60
        );
    }


    /**
     * 根据shopId获取门店证件状态
     * @param array $shopIds
     * @return mixed|void
     * @throws BaseException
     * @throws GuzzleException
     */
    public static function getShopLicenseStatus(array $shopIds)
    {
        return self::customRequest(
            'internal/shop/getShopLicenseStatus',
            RequestAlias::METHOD_GET,
            [
                'shopIds' => join(',', $shopIds)
            ]
        );
    }

    /**
     * 根据云巡店-稽核日期查询对应门店id
     * @param int $startTime
     * @param int $endTime
     * @return mixed|void
     * @throws BaseException
     * @throws GuzzleException
     */
    public static function getShopIdsByTourCruise(int $startTime, int $endTime)
    {
        return self::customCacheRequest(
            'internal/shop/getShopIdsByTourCruise',
            RequestAlias::METHOD_GET,
            [
                'startTime' => $startTime,
                'endTime'   => $endTime,
            ],
            null,
            5 * 60
        );
    }
}
